import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class TestEvalMirroredBoards extends TestCase {
    private static final Class thisClass = TestEvalMirroredBoards.class;

    public static void main(String[] args) {
        if (args.length >= 1 && args[0].equals("print")) {
            Board b = RandomBoard.randPieces();
            Board m = Board.mirrorBoard(b);
            GameEngine.printBoard(b);
            GameEngine.printBoard(m);
        } else if (args.length >= 1 && args[0].equals("text")) {
            junit.textui.TestRunner.run(thisClass);
        } else {
            junit.swingui.TestRunner.run(thisClass);
        }
    }

    public static Test suite() {
        return new TestSuite(thisClass);
    }

    public void testEvalMirroredBoards() {
        NewEval eval = new NewEval();
        for (int i = 0; i < 1000000; i++) {
            Board board = RandomBoard.randPieces();
            Board mirror = Board.mirrorBoard(board);

            assertTrue(board.isSane());
            assertTrue(mirror.isSane());

            int value = eval.eval(board);
            int mirrorValue = -eval.eval(mirror);

            if (value != mirrorValue) {
                System.out.println("At iteration " + i);
                System.out.println("These boards aren't correctly evaluated.");
                System.out.println("The original board:");
                GameEngine.printBoard(board);
                System.out.println("And its mirror:");
                GameEngine.printBoard(mirror);
            }
            assertEquals(value, mirrorValue);
        }
    }
}
